/**
 * PageMarket
 * SchedulLineView.java
 * com.android.pagemarket.ui.widget
 * 
 */
package com.android.pagemarket.ui.widget;

import android.content.Context;
import android.text.Html;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.android.pagemarket.R;
import com.android.pagemarket.io.protocol.out.SchedulLine;

/*********************************************************
 * @author : zhaohua
 * @version : 2012-11-11
 * @see : 
 * @Copyright : copyrights reserved by personal 2007-2012
 **********************************************************/
public class SchedulLineView extends LinearLayout
{
    private TextView degree;
    private TextView time_range;
    private ImageView ic_sperater;
    
    public  int lid;
    private SchedulLine.LineUnit unit;
    
    public SchedulLineView(Context context)
    {
        super(context);        
    }
    
    public SchedulLineView(Context context, AttributeSet attrs)
    {
        super(context, attrs);
    }
    
    @Override
    protected void onLayout(boolean changed, int l, int t, int r, int b)
    {
        super.onLayout(changed, l, t, r, b);
        if(ic_sperater != null) ic_sperater.layout(0, 0, ic_sperater.getWidth(), ic_sperater.getHeight());
    }
    
    @Override
    protected void onFinishInflate()
    {
        super.onFinishInflate();     
        degree = (TextView)findViewById(R.id.degree);
        time_range = (TextView)findViewById(R.id.time_range);
        ic_sperater = (ImageView)findViewById(R.id.ic_sperater);
    }

    public void bindData(int lid, SchedulLine.LineUnit unit)
    {
        this.lid = lid;
        this.unit = unit;
        
        setDegree(unit.degree + "&quot;");
        setTimeRange(unit.startTime + "-" + unit.endTime);
    }
    
    public void setDegree(String txt)
    {
        degree.setText(Html.fromHtml(txt));
    }
    
    public void setTimeRange(String txt)
    {
        time_range.setText(txt);
    }
    
    public void isShowSperater(SchedulLineView priUnit)
    {
        if(priUnit.unit.endIndex == unit.startIndex)
        {
            if(unit.startIndex_m - priUnit.unit.endIndex_m < 5)
            {
                ic_sperater.setVisibility(View.VISIBLE);
            }
        }
    }
    
    public int getLineIndex()
    {
        return lid;
    }
    
    public int getStartIndex()
    {
        return unit.startIndex;
    }
    
    public int getStartIndexM()
    {
        return unit.startIndex_m;
    }
    
    public int getEndIndex()
    {      
        return unit.endIndex;
    }
    
    public int getEndIndexM()
    {      
        return unit.endIndex_m;
    }
    
    // 是否是昨天过度到今天的线
    public boolean isPreLine()
    {
        return unit.mode == -1;
    }
    
    // 是否是今天过度到明天的线
    public boolean isNextLine()
    {
        return unit.mode == 1;
    }
}
